﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Item;

namespace Player
{
    public class NormalShopItemRandomer : IShopItemRandomer
    {
        private readonly ItemRandom.IItemRandomer itemRandomer;
        private readonly string[] arrRandomItemType;
        private readonly STShopData shopData;

        private List<STShopItemData> list;
        private int nRefreshTimes;
        private float fCoefficient;

        public NormalShopItemRandomer(STShopData shopData)
        {
            itemRandomer = new ItemRandom.NormalRandomer();
            arrRandomItemType = new string[]
            {
                ItemTypeConst.Damage,
                ItemTypeConst.Damage,
                ItemTypeConst.Assist,
                ItemTypeConst.Assist,
                ItemTypeConst.Army,
                ItemTypeConst.Gain,
                ItemTypeConst.Special,
            };
            this.shopData = shopData;
            nRefreshTimes = 0;
            fCoefficient = 1;

            list = new List<STShopItemData>();
        }

        public List<STShopItemData> GetRandomItemList()
        {
            nRefreshTimes++;
            list.Clear();


            //随机道具
            for (int i = 0; i < arrRandomItemType.Length; i++)
            {
                string[] tags = itemRandomer.GetRandomItems(new string[] { arrRandomItemType[i] }, 1);
                if (tags != null && tags.Length > 0 && !string.IsNullOrEmpty(tags[0]))
                    list.Add(new STShopItemData()
                    {
                        nCount = 1,
                        nPrice = (int)(shopData.nBasePrice * fCoefficient),
                        emItemType = EMShopItemType.Item,
                        strItemTag = tags[0],
                        bSold = false,
                    });
            }
            //钱换科研
            int sciencePrice = (int)(shopData.nBasePrice * fCoefficient);
            list.Add(new STShopItemData()
            {
                emItemType = EMShopItemType.Science,
                nPrice = sciencePrice,
                nCount = (int)(sciencePrice * shopData.fGoldToScienceCoefficient),
                bSold = false,
            });

            fCoefficient *= (float)shopData.fPriceIncrease;
            return list;
        }
    }
}